<template>
    <div class="register">
        <!-- Form -->

        <el-dialog title="新增用户" :visible.sync="addTeacherTable">
            <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="用户名" :label-width="formLabelWidth">
                    <el-input v-model="form.username" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="密码" :label-width="formLabelWidth">
                    <el-input v-model="form.password" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="邮箱" :label-width="formLabelWidth">
                    <el-input v-model="form.email" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="电话" :label-width="formLabelWidth">
                    <el-input v-model="form.tel" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="昵称" :label-width="formLabelWidth">
                    <el-input v-model="form.nikeName" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="收获地址">
                    <el-input type="textarea" v-model="form.address"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="addTeacherTable = false">取 消</el-button>
                <el-button type="primary" @click="onSubmit">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
export default {
  name: 'register',
  components: {
  },
  data: function() {
        return {
            addTeacherTable: true,
            formLabelWidth: '120px',
            form: {
                username: '',
                password: '',   
                email: '',
                tel: '',
                nikeName: '',
                address: '',
            },
        }
    },
    methods: {
        onSubmit() {
            //发送请求到后端
            this.$ax.post('/epai/user/userRegister', this.form)
            .then((response) => {
                if (response.data.success) {
                    this.$notify({
                        title: '新增成功',
                        message: '新增用户' + this.form.nikeName + "成功 ",
                        type: 'success'
                    });
                    this.addTeacherTable = false;
                      this.$router.push({path:'/login'});
                    ;
                } else {
                    this.$notify({
                        title: '新增失败',
                        message: response.data.message,
                        type: 'error',
                        duration: 1000
                    });
                }
            }).catch(error => {
                console.error(error);
            });
        },
    }
}
</script>